package com.jiayuge.server.config.kaptcha;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 功能: 验证吗配置文件
 *
 * @Program: yeb
 * @Date: 2021-11-17 10:20
 * @Author Jiayu.Yang
 */
@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha defaultKaptcha(){
        //验证码生成器
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        //配置
        Properties properties = new Properties();
        //边框配置
        properties.setProperty("kaptcha.border","yes");
        properties.setProperty("kaptcha.border.color","204,124,124");
        // 边框粗细度，默认为1
        properties.setProperty("kaptcha.border.thickness","1");
        //验证码
        properties.setProperty("kaptcha.session.key","code");
        //验证码字体配置
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        properties.setProperty("kaptcha.textproducer.font.size","30");
        properties.setProperty("kaptcha.textproducer.font.names", "微软雅黑");
        //验证码长度和间距
        properties.setProperty("kaptcha.textproducer.char.length","6");
        properties.setProperty("kaptcha.textproducer.char.space","4");
        //验证码生成的图片
        properties.setProperty("kaptcha.image.width","150");
        properties.setProperty("kaptcha.image.heigth","40");
        //验证码
        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");// 没有干扰

        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
